//
//  Dictionart+Extension.swift
//  CommonFoundation
//
//  Created by paliacci on 2018/3/29.
//  Copyright © 2018年 raniys. All rights reserved.
//

import Foundation

public extension Dictionary {
    
    /// Dictionart转JSON
    ///
    /// - Parameter dictionary: Dictionart
    /// - Returns: JsonString
    public func convertToJsonString() -> String {
        if (!JSONSerialization.isValidJSONObject(self)) {
            print("无法解析出JSONString")
            return ""
        }
        if let data = try? JSONSerialization.data(withJSONObject: self, options: []),
            let JSONString = NSString(data:data, encoding: String.Encoding.utf8.rawValue) {
            return JSONString as String
        }
        return ""
    }
}
